/* essential functions */

$get = function(id)
{
	if (typeof(id) == typeof(''))
		return document.getElementById(id);
	else
		return id;
}

$create = function(t, p)
{
	var n = document.createElement(t);
	for (k in p) n[k] = p[k];
	return n;
}

$addcls = function(n, c)
{
	var nd = $get(n);
	if (nd && !$hascls(nd, c))
		nd.className = nd.className.trim() + ' ' + c;
}

$delcls = function(n, c)
{
	var nd = $get(n);
	if (nd) nd.className = nd.className.replace(new RegExp('(^|\\s+)' + c + '(\\s+|$)', 'g'), ' ');
}

$hascls = function(n, c)
{
	var nd = $get(n);
	if (nd) return !!(nd.className.match(new RegExp('(^|\\s+)' + c + '(\\s+|$)', 'g')));
}

$show = function(n)
{
	$delcls(n, 'hidden');
}

$hide = function(n)
{
	$addcls(n, 'hidden');
}

$toggle = function(n)
{
	return $hascls(n, 'hidden') ? $show(n) : $hide(n);
}


String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/, '');
}

Array.prototype.unique = function()
{
	var o = {}, i, l = this.length;
	for(i = 0; i < l; ++i) o[this[i]] = this[i];
	this.splice(0, l);
	for(i in o) this.push(o[i]);
}